home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
optivc32
/
vdemow.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-06
|
15KB
|
343 lines
/*********************** VDEMOW.CPP ***********************************
* *
* Demo program for *
* O p t i V e c *
* with Borland C++ 4.x, 5.x, C++ Builder, *
* or Microsoft Visual C++ 5.0 or 6.0 *
* *
* Copyright 1996-1999 by Martin Sander *
* *
* *
* This sample program is meant to demonstrate how to use *
* OptiVec within your Windows programs. It is not intended *
* to demonstrate best Windows programming. *
* *
**************************************************************************/
/*
Borland C++, Command-line:
a) 32-bit: type
BCC32 -W vdemow.cpp vcf3w.lib
b) 16-bit: type
BCC -ml -W vdemow.cpp vcl3w.lib
Borland C++, IDE:
1. Open the new-project menu with Project/New.
2. Create a project VDEMOW in the OptiVec directory,
e.g., \bc\optivec.
3.a) 32-bit: Choose Application[EXE] for Win32 GUI, static linking,
single-thread.
3.b) 16-bit: Choose Application[EXE] for Windows3.x, memory model LARGE.
4. Hit OK.
5. In the Project window that will now be on the screen, delete the
nodes VDEMOW.DEF and VDEMOW.RC.
6.a) 32-bit: Add the node VCF3W.LIB.
6.b) 16-bit: Add the node VCL3W.LIB.
7. In Options/Project, be sure the include-file search path and the
library search path both include the respective OPTIVEC directories,
e.g.: \bc\optivec\include and bc\optivec\lib, resprectively
8. Compile and run.
Microsoft Visual C++:
1. Create a new project as a "Win32 application".
2. In the project settings, C/C++, Code Generation,
verify that single-thread debug is chosen.
3. Add \OptiVec\include to the include-file search path.
4. Add the files VDEMOW.CPP and OVVCSD.LIB to your project.
5. Compile and run.
*/
#include <windows.h> /* Compiler's include files */
#include <stdio.h>
#include <math.h>
#include <string.h>
#if defined __FLAT__ || defined _WIN32
#include <winbase.h>
#else
#include <dos.h>
#endif
#include <VFstd.h> /* OptiVec include files */
#include <VCFstd.h>
#include <VFmath.h>
#include <VCFmath.h>
#include <VIstd.h>
#include <Vgraph.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
HWND hWndMain;
fVector X1, X2, Y1, Y2, Y3, Y4, Spc, Freq, Win;
cfVector CX1, CX2;
iVector I1;
ui vsize, spcsize;
int vview;
#if defined __FLAT__ || defined WIN32 || defined _WIN32
struct _SYSTEMTIME tStart, tStop;
#else
struct time tStart, tStop;
#endif
NEWMATHERR
LONG FAR PASCAL MainMessageHandler (HWND, UINT, WPARAM, LPARAM);
void StartTime( void )
{
#if defined __FLAT__ || defined WIN32 || defined _WIN32
GetLocalTime( &tStart );
#else
gettime( &tStart );
#endif
}
double StopTime( void )
{
double tBegin, tEnd;
#if defined __FLAT__ || defined WIN32 || defined _WIN32
GetLocalTime( &tStop );
tBegin = (tStart.wHour * 60 + tStart.wMinute) * 60L
+ tStart.wSecond + tStart.wMilliseconds * 0.001;
tEnd = (tStop.wHour * 60 + tStop.wMinute) * 60L
+ tStop.wSecond + tStop.wMilliseconds * 0.001;
#else
gettime( &tStop );
tBegin = (tStart.ti_hour * 60 + tStart.ti_min) * 60L
+ tStart.ti_sec + tStart.ti_hund * 0.01;
tEnd = (tStop.ti_hour * 60 + tStop.ti_min) * 60L
+ tStop.ti_sec + tStop.ti_hund * 0.01;
#endif
return( tEnd - tBegin );
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR /* lpCmdLine */, int /* nCmdShow */)
{
MSG msg; /* MSG structure to pass to windows proc */
WNDCLASS wc;
char *AppName; /* Name for the window */
AppName = "VDemoW"; /* The name of this application */
if(!hPrevInstance)
{
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc= MainMessageHandler;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (hInstance, AppName);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = AppName;
wc.lpszClassName = AppName;
RegisterClass (&wc);
}
/* create application's Main window: */
hWndMain = CreateWindow (AppName,
"OptiVec Demo",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, /* Use default X, Y, and width */
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, /* Parent window's handle */
NULL, /* Default to Class Menu */
hInstance, /* Instance of window */
NULL); /* Create struct for WM_CREATE */
if (hWndMain == NULL)
{
MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION);
return (1);
}
ShowWindow(hWndMain, SW_SHOWMAXIMIZED); /* Display main window */
UpdateWindow(hWndMain);
while(GetMessage(&msg, NULL, 0, 0)) /* Main message loop */
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClass (AppName, hInstance);
return (msg.wParam);
}
LONG FAR PASCAL
MainMessageHandler(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HDC vDC;
PAINTSTRUCT ps;
char TimeMsg[100];
unsigned i, j;
float xt, A=1.2f, B=-0.13f, C=0.85f;
switch (Message) /* Windows Message Loop */
{
case WM_CREATE:
vsize = 1025;
spcsize = 128;
vview = 0;
I1 = VI_vector( vsize );
X1 = VF_vector( vsize );
X2 = VF_vector( vsize );
Y1 = VF_vector( vsize );
Y2 = VF_vector( vsize );
Y3 = VF_vector( vsize );
Y4 = VF_vector( vsize );
Spc= VF_vector( spcsize+1 );
Freq=VF_vector( spcsize+1 );
Win= VF_vector( 2*spcsize );
CX1 = VCF_vector( vsize );
CX2 = VCF_vector( vsize );
break;
case WM_PAINT:
vDC = BeginPaint(hWndMain, &ps);
V_initPlot( hWndMain, vDC );
switch( vview )
{
default: break;
case 0:
TextOut( vDC, 10, 10,
"This is a series of graphs illustrating VectorLib functions.", 60 );
TextOut( vDC, 10, 40,
"Always press the right mouse button to see the next view!", 56 );
TextOut( vDC, 10, 70,
"Press [Alt] [F4] to end the demonstration.", 41 );
break;
case 1:
TextOut( vDC, 0, 10, "Sine wave", 9 );
V_drawAxes( VF_min( X1, vsize/2 ), VF_max( X1, vsize/2 ),
-1.0, +1.0 );
VF_xyDataPlot( X1, Y1, vsize/2, PS_SOLID, LIGHTRED );
// show only half of all waves
break;
case 2: